(function ($) {
	"use strict";
    // superfish menu
    $(function () {
        $('ul.sf-menu').superfish({
		delay: 1000,
		animation:  {
			opacity:'show',
			height:'show'
			},
		disableHI:  false
		});
    });
    //prettyphoto		
    $("a[rel^='prettyPhoto'], a[rel^='lightbox']").prettyPhoto({
        theme: 'pp_default',
        default_width: 500,
        overlay_gallery: true
    });
	//comment form box click function
	var $submit_button;
	var $website_box;
	$submit_button = $(".form-submit #submit");
	$website_box = $(".last-input input");
	$submit_button.click(function() {
            if( $website_box.attr("value") === "Website" ) {
 
                // Set it to an empty string
                $website_box.attr("value", "");
            }
	});
	// skills percentage
	$('.skill').each(function(){
		var dataperc;
		dataperc = $(this).attr('data-perc'),
		$(this).find('.skill-bar').animate({ "width" : dataperc + "%"}, dataperc*20);
	});
	//tooltip
    $(".tool-tip-content").hover(function () {
        $(this).next(".tooltip").stop(true, true).animate({
            opacity: "show",
            bottom: "25"
        }, "slow");
    }, function () {
        $(this).next(".tooltip").animate({
            opacity: "hide",
            bottom: "25"
        }, "fast");
    });
	//toggles
    $(".toggle-title").toggle(
    function () {
        $(this).addClass('toggle-active');
        $(this).siblings('.toggle-content').slideDown("fast");
    }, function () {
        $(this).removeClass('toggle-active');
        $(this).siblings('.toggle-content').slideUp("fast");
    });
	
	//tabs and accordions
    $(function () {
        //accordion
        $(".accordion").fptabs("div.pane", {
            tabs: '.tab',
            effect: 'slide'
        });
        //tabs
        $("ul.tabs, ul.tabbed-tabs").fptabs("div.panes > div, div.tabbed-panes > div", {
            effect: 'fade'
        });
    });
    //vertical tabs
    $(function () {
        $('#vertical-tabs, #vertical-tabs1, #vertical-tabs2, #vertical-tabs3, #vertical-tabs4, #vertical-tabs5, #vertical-tabs6, #vertical-tabs7, #vertical-tabs8, #vertical-tabs9, #vertical-tabs10').tabs({
            fx: [{
                opacity: 'toggle',
                duration: 90
            }, // hide option
            {
                opacity: 'toggle',
                duration: 90
            }]
        }); // show option
    });
	
	//styled form selects
	jQuery.fn.styledSelect = function(options) {
		var isFF2 = jQuery.browser.mozilla && jQuery.browser.version.indexOf('1.8.')==0;
		var prefs = {
			coverClass : 'select-replace-cover',
			innerClass : 'select-replace',
			adjustPosition : { top:0, left:0 },
			selectOpacity : 0
			}
		if (options) jQuery.extend(prefs,options);
		return this.each( function() {
			if (isFF2) return false;
			var selElm = jQuery(this);
			selElm.wrap('<span><'+'/span>');
			selElm.after('<span><'+'/span>');
			var selReplace = selElm.next();
			var selCover = selElm.parent();
			selElm.css({
				'opacity':prefs.selectOpacity,
				'visibility':'visible',
				'position':'absolute',
				'top':0,
				'left':0,
				'display':'inline',
				'z-index':1
				});
			selCover.addClass(prefs.coverClass).css({
				'display':'inline-block',
				'position':'relative',
				'top':prefs.adjustPosition.top,
				'left':prefs.adjustPosition.left,
				'z-index':0,
				'vertical-align':'middle',
				'text-align':'left'
				});
			selReplace.addClass(prefs.innerClass).css({
				'display':'block',
				'white-space':'nowrap'
				});

			selElm.bind('change',function() {
				jQuery(this).next().text(this.options[this.selectedIndex].text);
				}).bind('resize',function() {
				jQuery(this).parent().width( jQuery(this).width()+'px' );
				});
			selElm.trigger('change').trigger('resize');
		});
	}

	$('.search-box select').styledSelect();
	
	//twitter feed
	$.fn.twitter = function(username, count, callback){
	
		var $twitHolder = $(this);
		var tHr = '';
	
		$.getJSON("https://api.twitter.com/1/statuses/user_timeline.json?screen_name="+username+"&count="+count+"&callback=?",
			 function(data){

			  $.each(data, function(i,item){
			  
				if(i==0) $twitHolder.empty();

          		$twitHolder.append('<div class="tweet">' + clean(item.text) + '</div>');

				});

			 	callback();

		});

	};

	function timeAgo(dateString) {
        var rightNow = new Date();
        var then = new Date(dateString);
         
        if ($.browser.msie) {
            // IE can't parse these crazy Ruby dates
            then = Date.parse(dateString.replace(/( \+)/, ' UTC$1'));
        }
 
        var diff = rightNow - then;
 
        var second = 1000,
        minute = second * 60,
        hour = minute * 60,
        day = hour * 24,
        week = day * 7;
 
        if (isNaN(diff) || diff < 0) {
            return ""; // return blank string if unknown
        }
 
        if (diff < second * 2) {
            // within 2 seconds
            return "right now";
        }
 
        if (diff < minute) {
            return Math.floor(diff / second) + " seconds ago";
        }
 
        if (diff < minute * 2) {
            return "1 minute ago";
        }
 
        if (diff < hour) {
            return Math.floor(diff / minute) + " minutes ago";
        }
 
        if (diff < hour * 2) {
            return "1 hour ago";
        }
 
        if (diff < day) {
            return  Math.floor(diff / hour) + " hours ago";
        }
 
        if (diff > day && diff < day * 2) {
            return "yesterday";
        }
 
        if (diff < day * 365) {
            return Math.floor(diff / day) + " days ago";
        }
 
        else {
            return "over a year ago";
        }
    }
	  
	function link(tweet) {
        return tweet.replace(/\b(((https*\:\/\/)|www\.)[^\"\']+?)(([!?,.\)]+)?(\s|$))/g, function(link, m1, m2, m3, m4) {
          var http = m2.match(/w/) ? 'http://' : '';
          return '<a class="twtr-hyperlink" target="_blank" href="' + http + m1 + '">' + ((m1.length > 25) ? m1.substr(0, 24) + '...' : m1) + '</a>' + m4;
        });
    };
	
	function at(tweet){
		return tweet.replace(/\B[@@]([a-zA-Z0-9_]{1,20})/g, function(m, username) {
          return '<a target="_blank" class="twtr-atreply" href="http://twitter.com/intent/user?screen_name=' + username + '">@' + username + '</a>';
        });
	}
	
	function list(tweet){
        return tweet.replace(/\B[@@]([a-zA-Z0-9_]{1,20}\/\w+)/g, function(m, userlist) {
          return '<a target="_blank" class="twtr-atreply" href="http://twitter.com/' + userlist + '">@' + userlist + '</a>';
        });
	
	}
	
	function hash(tweet){
        return tweet.replace(/(^|\s+)#(\w+)/gi, function(m, before, hash) {
          return before + '<a target="_blank" class="twtr-hashtag" href="http://twitter.com/search?q=%23' + hash + '">#' + hash + '</a>';
        });
	
	}
	
	function clean(tweet){
        return hash(at(list(link(tweet))));
	}
	
	//initialize twitter feed
	$('.twitter-feed').twitter($('.twitter-feed').data('user'), 10, function(){
		var $twitts = $('.twitter-feed').children('.tweet');
		var i = 0;
		if($twitts.eq(i).height() > 50)
			$twitts.eq(i).css('marginTop', -10)
		setInterval(function(){
			$twitts.eq(i).fadeOut(200);
			i = ++i == $twitts.length ? 0 : i;
			$twitts.eq(i).delay(200).fadeIn(200);
			if($twitts.eq(i).height() > 50) 
				$twitts.eq(i).css('marginTop', -10);
			else
				$twitts.eq(i).css('marginTop', 0);
		}, 5000);
	});

    //end
})(jQuery);

/* ------------------------------------------------------------------------ */
/* EOF
/* ------------------------------------------------------------------------ */